home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / header / header.m
Text File  |  1987-05-23  |  9KB  |  357 lines

  1. ;************************************************************************
  2. ;*                                                                        *
  3. ;*             H E A D E R . M - Generate Standard File Prologue            *
  4. ;*                                                                        *
  5. ;************************************************************************
  6.  
  7. ;************************************************************************
  8. ;*                                                                        *
  9. ;*              Copyright (c) Hardwood Software Associates 1987            *
  10. ;*                                                                        *
  11. ;*                       Hardwood Software Associates                        *
  12. ;*                              364 Benson Road                            *
  13. ;*                           Northbridge, Ma 01534                        *
  14. ;*                                                                        *
  15. ;************************************************************************
  16.  
  17. ;************************************************************************
  18. ;*            H E A D E R . M    E D I T    L O G
  19. ;*
  20. ;*    Edit    Date    Person        Modification
  21. ;*    ----    ----    ------        ------------
  22. ;*  3.13  16-Apr-87 R. Evans     Add Alt-A - header block
  23. ;*  4.01   9-May-87 R. Evans    Change name to header
  24. ;*                                Use _init
  25. ;*
  26. ;************************************************************************
  27.  
  28. ;************************************************************************
  29. ;*                                                    +-------------------+
  30. ;*    Author: R. Evans                                | F U N C T I O N S |
  31. ;*    Date:    April, 1987                                +-------------------+
  32. ;*
  33. ;* The environment string "owner" points to a complete path name of a
  34. ;* file that contains the name of the owner of the copyright as the first
  35. ;* line.  Lines following the owner's name are displayed after the
  36. ;* copyright name.  This data is usually the address of the owner.
  37. ;*
  38. ;* Two different prologues are created:
  39. ;*                C file prologues
  40. ;*                Assembler/Brief macros
  41. ;* These formats differ only in the comment character.
  42. ;*
  43. ;* The header macros should be called whenever a new file is editted.
  44. ;* This is done bye inserting a (header) call in "startup.m" for each
  45. ;* file type desired.
  46. ;*
  47. ;* A prologue is created whenever the third character on the first line
  48. ;* is not a "*".  The header may be aborted by typeing escape at
  49. ;* the description prompt.
  50. ;*
  51. ;* Several other useful macros are included:
  52. ;*    c_comment   - Generate an empty comment in column 49 for C
  53. ;*    asm_comment - Generate an empty comment in column 49 for ASM
  54. ;*  comment     - Call c_comment or asm_comment depending upon
  55. ;*                  extension (usually attached to a key)
  56. ;*    function_header - Insert a functin header
  57. ;************************************************************************
  58.  
  59. #define LINE_END    73                            ; width of heading
  60.  
  61. (macro _init                                                    ;++4.02
  62.     (                                                            ;++4.02
  63.     (string stars)                                                ;++4.02
  64.     (global stars)                                                ;++4.02
  65.     (= stars "**********************************************************************")
  66.     )                                                            ;++4.02
  67. ) ;Of _init                                                        ;++4.02
  68.  
  69. ; Move to column 49 and insert a C comment
  70.  
  71. (macro c_comment                                                ;++4.02
  72.     (
  73.         (int col)
  74.         (end_of_line)
  75.         (inq_position NULL col)
  76.         (if (> 49 col)
  77.             (move_abs 0 49)
  78.         ;else
  79.             (move_rel 0 1)
  80.         )
  81.         (insert "/*  */")
  82.         (move_rel 0 -3)
  83.     )
  84. ) ; Of c_comment
  85. ; Move to column 49 and insert a ASM comment
  86.  
  87. (macro asm_comment
  88.     (
  89.         (int col)
  90.         (end_of_line)
  91.         (inq_position NULL col)
  92.         (if (> 49 col)
  93.             (move_abs 0 49)
  94.         ;else
  95.             (move_rel 0 1)
  96.         )
  97.         (insert "\; ")
  98.     )
  99. )
  100.  
  101. (macro comment                                                    ;++4.02
  102.     (
  103.     (int file_type)
  104.     (global file_type)
  105.     (init_header)
  106.     (if (== file_type 1) (c_comment) (asm_comment))
  107.     )
  108. ) ; Of comment
  109.  
  110. (macro init_header
  111.     (
  112.     (string temp)
  113.     (inq_names NULL temp NULL)
  114.     (if (== temp "c") (= file_type 1) (= file_type 2))
  115.     ) ; Of init_header
  116. )
  117.  
  118. (macro function_header
  119.     (
  120.     (string bname)
  121.     (int line col)
  122.  
  123.     (init_header)
  124.     (if (get_parm 0 bname "Function: ")                ; File name
  125.         (
  126.         (create_header bname)
  127.         (if (== file_type 1)
  128.             (
  129.             (insert bname)
  130.             (insert " (")
  131.             (inq_position line col)
  132.             (insert ")\n{\n} /* Of ")
  133.             (insert bname)
  134.             (insert " */\n")
  135.             (move_abs line col)
  136.             )
  137.         )
  138.         )
  139.     )
  140.     ) ; Of function_header
  141. )
  142. (macro header
  143.     (
  144.     (int year month day)
  145.     (string bname month_string b_name)
  146.     (string temp_str)
  147.  
  148.     (init_header)
  149.     (date year month day month_string)
  150.     (inq_names NULL NULL bname)                    ; get name of buffer
  151.     (wide_string bname b_name)
  152.  
  153.     (move_abs 1 3)                                ; Start of file after comment
  154.     (if (!= (read 1) "*")
  155.         (
  156.             (move_abs 1 1)                        ; To start of file
  157.  
  158. ;*** Insert Block defining file
  159.             (if (create_header bname)            ; Create header block
  160.                 (
  161.                 (message "Create standard file prologue")
  162.  
  163.     ;*** Insert copyright notes
  164.                 (do_line_2 stars)                    ; All stars
  165.                 (do_copy)                            ; Copyright
  166.                 (do_line_2 stars)
  167.                 (insert "\n")                        ; Skip a Line
  168.  
  169.     ;*** Insert edit log
  170.                 (do_line_s stars)                    ; Line of all stars
  171.                                                     ; Edit heading
  172.                     (sprintf temp_str "\t\t\t%s   E D I T    L O G" b_name)
  173.                     (do_line temp_str)
  174.                 (do_line "")                        ; Blank line
  175.                                                     ; Edit heading
  176.                     (do_line "\tEdit\tDate\tPerson\t\tModification")
  177.                                                     ; Edit heading
  178.                     (do_line "\t----\t----\t------\t\t------------")
  179.                 (do_line "")                        ; Blank line
  180.                 (do_line_e stars)                    ; Line of all stars
  181.                 (insert "\n")                        ; Skip a Line
  182.  
  183.     ;*** Insert function description heading
  184.                 (do_line_s stars)                    ; Line of all stars
  185.                 (do_line "")                        ; FUNCTION
  186.                     (move_rel -1 0 ) (move_abs 0 LINE_END) (move_rel 0 -20)
  187.                     (insert "+-------------------+\n")
  188.                 (do_line "\tAuthor: R. Evans")        ; FUNCTION
  189.                     (move_rel -1 0 ) (move_abs 0 LINE_END) (move_rel 0 -20)
  190.                     (insert "| F U N C T I O N S |\n")
  191.                                                     ; FUNCTION
  192.                     (sprintf temp_str "\tDate:\t%s, %d" month_string year)
  193.                     (do_line temp_str)
  194.                     (move_rel -1 0 ) (move_abs 0 LINE_END) (move_rel 0 -20)
  195.                     (insert "+-------------------+\n")
  196.                 (do_line "")                        ; Blank line
  197.                 (do_function)
  198.                 (do_line_e stars)
  199.                 )
  200.             )
  201.         )
  202.     )
  203.     (top_of_buffer)
  204.  
  205.     ) ; Of header
  206. )
  207.  
  208. (macro do_line_2
  209.     (
  210.     (string temp)
  211.     (get_parm 0 temp)
  212.     (if (== file_type 1) (insert "/*") (insert "\;*"))
  213.     (move_abs 0 (+ 2 (/ (- LINE_END (strlen temp)) 2)))
  214.     (insert temp)
  215.     (move_abs 0 LINE_END)
  216.     (if (== file_type 1) (insert "*/\n") (insert "*\n"))
  217.     ) ; Of do_line_2
  218. )
  219.  
  220. (macro do_line_s
  221.     (
  222.     (string temp)
  223.     (get_parm 0 temp)
  224.     (if (== file_type 1) (insert "/*") (insert "\;*"))
  225.     (move_abs 0 (+ 2 (/ (- LINE_END (strlen temp)) 2)))
  226.     (insert temp)
  227.     (insert "*\n")
  228.     ) ; Of do_line_s
  229. )
  230.  
  231. (macro do_line_e
  232.     (
  233.     (string temp)
  234.     (get_parm 0 temp)
  235.     (if (== file_type 1) (insert " *") (insert "\;*"))
  236.     (move_abs 0 (+ 2 (/ (- LINE_END (strlen temp)) 2)))
  237.     (insert temp)
  238.     (if (== file_type 1) (insert "*/\n") (insert "*\n"))
  239.     ) ; Of do_line_e
  240. )
  241.  
  242. (macro do_line
  243.     (
  244.     (string temp)
  245.     (get_parm 0 temp)
  246.     (if (== file_type 1) (insert " *") (insert "\;*"))
  247.     (insert temp)
  248.     (insert "\n")
  249.     ) ; Of do_line
  250. )
  251.  
  252. (macro do_copy
  253.     (
  254.     (string owner temp)
  255.     (int year file)
  256.     (int old_buffer copy_buffer no_line)
  257.  
  258.     (date year)
  259.     (= owner (inq_environment "OWNER"))
  260.     (if (== 0 (strlen owner)) 
  261.         (
  262.         (get_parm 1 owner "Owner:")
  263.         (= file 0)
  264.         (= no_line 0)
  265.         )
  266.     ; else
  267.         (
  268.         (= file 1)
  269.         (= old_buffer (inq_buffer))
  270.         (set_buffer (= copy_buffer (create_buffer "Comments" owner 1)))
  271.         (end_of_buffer)
  272.         (inq_position no_line)
  273.         (top_of_buffer)
  274.         (-- no_line)
  275.         (= owner (read))
  276.         (= owner (substr owner 1 (- (strlen owner) 1)))
  277.         (move_rel 1 0)
  278.         (set_buffer old_buffer)
  279.         (-- no_line)
  280.         )
  281.     )
  282.     (do_line_2 "")
  283.     (sprintf temp "Copyright (c) %s %d" owner year)
  284.     (do_line_2 temp)
  285.     (do_line_2 "")
  286.     (do_line_2 owner)
  287.     (while (> no_line 0)
  288.         (
  289.         (set_buffer copy_buffer)
  290.         (= temp (read))
  291.         (move_rel 1 0)
  292.         (set_buffer old_buffer)
  293.         (do_line_2 (substr temp 1 (- (strlen temp) 1)))
  294.         (-- no_line)
  295.         )
  296.     )
  297.     (do_line_2 "")
  298.     (if (== 1 file) (delete_buffer copy_buffer))
  299.     ) ; Of do_copy
  300. )
  301.  
  302. (macro do_function
  303.     (
  304.     (do_line "*************")
  305.     (do_line " SYNOPSIS:")
  306.     (do_line "")
  307.     (do_line " DESCRIPTION:")
  308.     (do_line "")
  309.     (do_line " RETURNS:")
  310.     (do_line "")
  311.     (do_line " CAUTIONS:")
  312.     (do_line "")
  313.     ) ; Of do_function
  314. )
  315.  
  316. (macro create_header
  317.     (
  318.     (string bname b_name temp_str)
  319.     (get_parm 0 bname)                            ; Name
  320.     (wide_string bname b_name)
  321.     (sprintf temp_str "%s description:" (upper bname))
  322.     (if (get_parm 1 bname temp_str)
  323.         (
  324.         (insert "\n") (move_rel -1 0)            ; Insert a blank line to work from
  325.         (do_line_2 stars)                        ; First line of all stars
  326.         (do_line_2 "")                            ; Blank line
  327.         (= temp_str b_name) (+= temp_str "- ") (+= temp_str bname)
  328.         (do_line_2 temp_str)
  329.         (do_line_2 "")                            ; Blank line
  330.         (do_line_2 stars)                        ; All stars
  331.         (insert "\n")                            ; Skip a Line
  332.         (returns 1)
  333.         )
  334.     ; else
  335.         (returns 0)
  336.     )
  337.     ) ; Of create_header
  338. )
  339.  
  340. (macro wide_string
  341.     (
  342.     (string input output)
  343.     (int i)
  344.     (get_parm 0 input)
  345.     (= input (upper input))
  346.     (= i 1)
  347.     (while (<= i (strlen input))
  348.         (
  349.             (+= output (substr input i 1))
  350.             (+= output " ")
  351.             (++ i)
  352.         )
  353.     )
  354.     (put_parm 1 output)
  355.     ) ; Of wide_string
  356. )
  357.